home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / jmtl028c.zip / LOOKUP.C < prev    next >
C/C++ Source or Header  |  1994-03-17  |  6KB  |  206 lines

  1.  
  2. #include <stdio.h>
  3. #include <exec/types.h>
  4. #include <exec/execbase.h>
  5. #include <exec/nodes.h>
  6. #include <exec/lists.h>
  7. #include <exec/devices.h>
  8. #include <exec/io.h>
  9. #include <exec/libraries.h>
  10. #include <devices/serial.h>
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13. #include <utility/hooks.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16.  
  17. #include "xferq/xferq.h"
  18. #include "xferq/xferq_pragmas.h"
  19.  
  20. #ifdef TRAPLIST
  21. #include "h/trap.h"
  22. #define NODELIST_NAME TRAPLIST_NAME
  23. #define NODELIST_VER TRAPLIST_VER
  24. #endif
  25.  
  26. #ifdef IGEN
  27. #include "h/igen.h"
  28. #endif
  29.  
  30. extern struct Library *XferqBase;
  31.  
  32. void lookup(struct structup *lookupstruct);
  33. void scanlist(char *list, struct structup *lookupstruct);
  34.  
  35. struct structup {
  36.     char found;
  37.     char nodelist[50];
  38.     char address[50];
  39.     char phone[50];
  40.     char sysop[50];
  41.     char type[6];
  42.     char password[20];
  43.     char city[20];
  44.     char flags[30];
  45.     char system[40];
  46.     char baud[10];
  47.     char hub[10];
  48.     char region[10];
  49.     char cost[10];
  50. };
  51.  
  52. struct Library *NodelistBase;
  53.  
  54. const char *const nl_keys[] =
  55.     { "Node", "Host", "Hold", "Hub", "Pvt", "Point", "Zone", "Region", "Down" };
  56.  
  57. void lookup(struct structup *lookupstruct)
  58. {
  59.  
  60.     NodeList the_nodelist;
  61.     NodeDesc *node_desc;
  62.  
  63.     static char temp[255], address[50];
  64.  
  65.     if(!(NodelistBase = OpenLibrary(NODELIST_NAME, NODELIST_VER)))
  66.     {
  67.         printf("Can't open library\n");
  68.         exit(5);
  69.     }
  70.  
  71.     if(the_nodelist = NLOpen(lookupstruct->nodelist, 0))
  72.     {
  73.          Addr find_me;
  74.  
  75.          int i,j;
  76.  
  77.          strcpy(address, lookupstruct->address);
  78.  
  79.          for(i=0;address[i]>35;i++);
  80.  
  81.          i++;
  82.          for(j=0;address[i]<58;j++,i++)
  83.             temp[j]=address[i];
  84.          temp[j]=0;
  85.          find_me.Zone = atoi(temp);
  86.  
  87.          i++;
  88.          for(j=0;address[i]>47;j++,i++)
  89.             temp[j]=address[i];
  90.          temp[j]=0;
  91.          find_me.Net = atoi(temp);
  92.  
  93.          i++;
  94.          for(j=0;address[i]>46;j++,i++)
  95.             temp[j]=address[i];
  96.          temp[j]=0;
  97.          find_me.Node = atoi(temp);
  98.  
  99.          i++;
  100.          for(j=0;address[i];j++,i++)
  101.             temp[j]=address[i];
  102.          temp[j]=0;
  103.          find_me.Point= atoi(temp);
  104.  
  105.          if(node_desc = NLFind(the_nodelist, &find_me, 0))
  106.          {
  107.              lookupstruct->found = 1;
  108.              strcpy(lookupstruct->phone, node_desc->Phone);
  109.              strcpy(lookupstruct->sysop, node_desc->Sysop);
  110.              strcpy(lookupstruct->type, "FIDO");
  111.              for (i=0;lookupstruct->password[i]=toupper(node_desc->Passwd[i]);i++);
  112.  
  113.              strcpy(lookupstruct->city, node_desc->City);
  114.              strcpy(lookupstruct->flags, node_desc->Flags);
  115.              strcpy(lookupstruct->system, node_desc->System);
  116.              sprintf(lookupstruct->baud, "%ld", node_desc->BaudRate);
  117.              sprintf(lookupstruct->hub, "%ld", node_desc->Hub);
  118.              sprintf(lookupstruct->region, "%ld", node_desc->Region);
  119.              sprintf(lookupstruct->cost, "%ld", node_desc->Cost);
  120.  
  121.              for (i=0;i<strlen(lookupstruct->city);i++)
  122.                 if (lookupstruct->city[i]==' ')
  123.                    lookupstruct->city[i]='_';
  124.  
  125.              for (i=0;i<strlen(lookupstruct->sysop);i++)
  126.                 if (lookupstruct->sysop[i]==' ')
  127.                    lookupstruct->sysop[i]='_';
  128.  
  129.              for (i=0;i<strlen(lookupstruct->flags);i++)
  130.                 if (lookupstruct->flags[i]==' ')
  131.                    lookupstruct->flags[i]='_';
  132.  
  133.              if (strlen(lookupstruct->password) <2) strcpy(lookupstruct->password, "-");
  134.              if (strlen(lookupstruct->city) <2) strcpy(lookupstruct->city, "-");
  135.              if (strlen(lookupstruct->sysop) <2) strcpy(lookupstruct->sysop, "-");
  136.  
  137.          }
  138.          NLClose(the_nodelist);
  139.     }
  140.     else
  141.     {   
  142.         printf("Library Can't Open Nodelist\n");
  143.     }
  144.     CloseLibrary(NodelistBase);
  145.     return;
  146. }
  147.  
  148. void scanlist(char *list, struct structup *lookupstruct)
  149. {
  150.     FILE *fp;
  151.  
  152.     static char temp[255], addres[50], phone[50], type[6], password[10];
  153.     static char flags[40], city[40], sysop[40], source[50];
  154.  
  155.     int i;
  156.  
  157.     fp = fopen(list, "r");
  158.     if (fp)
  159.     { 
  160.  
  161.       while ((fgets(temp, 253, fp) != NULL) && (lookupstruct->found!=1))
  162.       {
  163.  
  164.         if ((temp[0]=='#') || (temp[0]==';')) continue;
  165.  
  166.         sscanf(temp, "%s %s %s %s %s %s %s", source, phone, type, password,
  167.            flags, city, sysop);
  168. /*
  169.  
  170.         if(addr=XfqGetAddressTags(source,NULL,XQ_Mandatory,XQADDR_NODE,
  171.                 XQ_Optional,XQADDR_ANYTHING,TAG_DONE))
  172.         {
  173.            if(address=XfqPutAddressTags(addr, XQ_Mandatory,XQADDR_ANYTHING,
  174.                 XQ_Optional,XQADDR_ANYTHING,TAG_DONE))
  175.            {
  176.               XfqExamObjectTags(addr,XQ_Domain,&domain,TAG_DONE);
  177.               for(i=0;addres[i]=toupper(address[i]);i++);
  178.               XfqDropObject(address);
  179.               XfqDropObject(addr);
  180.            }
  181.         }
  182.         else
  183. */
  184.            for(i=0;addres[i]=toupper(source[i]);i++);
  185.  
  186.         if (!strcmp(addres, lookupstruct->address))
  187.         {
  188.             lookupstruct->found = 1;
  189.             strcpy(lookupstruct->phone, phone);
  190.             strcpy(lookupstruct->type, type);
  191.  
  192.             if (password[0]!='-')
  193.                strcpy(lookupstruct->password, password);
  194.             if ((sysop[0]!='-') && (sysop[0]))
  195.                strcpy(lookupstruct->sysop, sysop);
  196.             if ((city[0]!='-') && (city[0]))
  197.                strcpy(lookupstruct->city, city);
  198.             strcpy(lookupstruct->flags, flags);
  199.     }
  200.      }
  201.    }
  202.  
  203.    return;
  204. }
  205.  
  206.